import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.rsbot.bot.Bot;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.script.Calculations;
import org.rsbot.script.Constants;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSTile;

/**
 * 
 * MysticCrabsPwn3r.java
 * 
 * @Author Mouchicc ( mr.mourad@live.nl )
 * 
 * @Date 2009
 * 
 * @version 1.0
 * 
 * 
 */

@ScriptManifest(authors = { "Mouchicc" }, category = "Combat", name = "MCrabsEnums", version = 1.0, description = "<html><body>"
		+ "<b><font size=\"6\" color=\"red\">"
		+ "MCrabEnums v 1.0"
		+ "</font></b><br>"
		+ "<font size=\"3\" color=\"red\">Please start @ the eastern Crabs.<br></font>"
		+ "<font size=\"8\">== Options and Settings ==</font>"
		+ "<b><tr><td>Use Potions:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"pot\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>"
		+ "<b><tr><td>Pick Charms:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"charm\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>"
		+ "<b><tr><td>Arrow Pickup:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"ranged\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>"
		+ "<tr><td><b>Eat At:</b>&nbsp<input type=\"text\" name=\"eatt\" size=\"4\"</center></td></tr>"
		+ "<b><tr><td>Attack Style:</b></td><td width=\"140\"><center><select name=\"skill\"><option>Strength<option>Attack<option>Defence<option>Rapid Ranged<option>Accurate Ranged<option>Longrange Ranged</select></center></td><td width=\"135\"></b></center></td></tr></tr>"
		+ "<tr><td><b>Pick Item ID:</b></td><td colspan=\"3\"><center><b>Item ID:</b>&nbsp<input type=\"text\" name=\"ItemID1\" size=\"4\"></center></td></tr>"
		+ "</center></center></body></html>")
public class MCrabsEnums extends Script implements ServerMessageListener,
		PaintListener {

	ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);

	boolean anyCharms = false;
	boolean anyCustoms = false;
	boolean anyArrows = false;

	BufferedImage MCSeries = null;
	String[] attackStyles = new String[] { "Strength", "Attack", "Defence",
			"Rapid Ranged", "Accurate Ranged", "Longrange Ranged" };
	private String status = "Chilling..";
	String sendText;
	RSTile[] path;
	int GambleInt;
	public String[] extra2 = new String[] { " =)", " =p", " =D", " XD", " =]" };
	public String[] nahhhtext = new String[] { "Nahh", "I dont want to",
			"Is your name on it? ", "It isn't yours", "Off u", "Tomorrow",
			"Noob..", "No?" };
	int randomWield = random(70, 120);
	int curStatExp;
	long lvls = 0;
	long startTime = System.currentTimeMillis();
	int startLvl;
	int startExp;
	int stat;
	String skill;
	int startxp;
	int[] CRAB_ROCK_MODE = { 1266, 1268 };
	int[] CRAB_NORMAL_MODE = { 1265, 1267 };
	public int itemIndex;
	public int ITPID = 0000;
	public static int[] potID;
	int CurSTAT;
	int RealSTAT;
	public int[] charms = { 12158, 12159, 12160, 12163 };
	public int fightMode;
	public boolean doingspec;
	public boolean potion;
	public boolean charmpickup;
	public boolean takeSomeItem;
	public boolean ranging;
	int eatAT;
	int tehArrows;
	int runEnergy = random(25, 60);
	public static int[] FoodID = { 1895, 1893, 1891, 4293, 2142, 291, 2140,
			3228, 9980, 7223, 6297, 6293, 6295, 6299, 7521, 9988, 7228, 2878,
			7568, 2343, 1861, 13433, 315, 325, 319, 3144, 347, 355, 333, 339,
			351, 329, 3381, 361, 379, 380, 10136, 5003, 379, 365, 373, 374,
			7946, 385, 397, 391, 3369, 3371, 3373, 2309, 2325, 2333, 2327,
			2331, 2323, 2335, 7178, 7180, 7188, 7190, 7198, 7200, 7208, 7210,
			7218, 7220, 2003, 2011, 2289, 2291, 2293, 2295, 2297, 2299, 2301,
			2303, 1891, 1893, 1895, 1897, 1898, 1899, 1900, 1901, 1902, 7072,
			7062, 7078, 7064, 7084, 7082, 7066, 7068, 1942, 6701, 6703, 7054,
			6705, 7056, 7060, 2130, 1985, 1993, 1989, 1978, 5763, 5765, 1913,
			5747, 1905, 5739, 1909, 5743, 1907, 1911, 5745, 2955, 5749, 5751,
			5753, 5755, 5757, 5759, 5761, 2084, 2034, 2048, 2036, 2217, 2213,
			2205, 2209, 2054, 2040, 2080, 2277, 2225, 2255, 2221, 2253, 2219,
			2281, 2227, 2223, 2191, 2233, 2092, 2032, 2074, 2030, 2281, 2235,
			2064, 2028, 2187, 2185, 2229, 6883, 1971, 4608, 1883, 1885, 403 };

	RSTile ToCenter = new RSTile(2703, 3727);
	RSTile goDown = new RSTile(2706, 3698);
	RSTile goUp = new RSTile(2708, 3722);

	@Override
	public String getScriptDescription() {
		String html = "";
		html += "<html>";
		html += "<head>";
		html += "<style type='text/css'> body {text-align:center; background-color: white; color: black;}</style>";
		html += "</head>";
		html += "<body>";
		html += "<center>";
		html += "<b><font size=\"6\" color=\"red\">" + properties.name() + " v"
				+ properties.version() + " M" + "</font></b><br>";
		html += "<font size=\"3\" color=\"red\">Please start @ the eastern Crabs.<br></font>";
		html += "<center><table border=\"0\"><tr><td colspan=\"5\"><center><font size=6><b>== Options and Settings ==</b></font></center></td></tr><tr><td colspan=4><hr></td></tr><tbody><tr><td width=\"135\">";
		html += "<b>Use Special:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"spec\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr>";
		html += "<b><tr><td>Use Potions:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"pot\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>";
		html += "<b><tr><td>Pick Charms:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"charm\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>";
		html += "<b><tr><td>Arrow Pickup:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"ranged\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr></tr>";
		html += "<tr><td><b>Eat At:</b>&nbsp<input type=\"text\" name=\"eatt\" size=\"4\"</center></td></tr>";
		html += "<b><tr><td>Attack Style:</b></td><td width=\"140\"><center><select name=\"skill\"><option>Strength<option>Attack<option>Defence<option>Rapid Ranged<option>Accurate Ranged<option>Longrange Ranged</select></center></td><td width=\"135\"></b></center></td></tr></tr>";
		html += "<tr><td><b>Pick Item ID:</b></td><td colspan=\"3\"><center><b>Item ID:</b>&nbsp<input type=\"text\" name=\"ItemID1\" size=\"4\"></center></td></tr>";
		html += "</center>";
		html += "</center></body>";
		html += "</html>";
		return (html);
	}

	// What to load on Start
	@SuppressWarnings("deprecation")
	@Override
	public boolean onStart(Map<String, String> args) {
		Bot.getEventManager().addListener(PaintListener.class, this);
		Bot.getEventManager().addListener(ServerMessageListener.class, this);
		log("Credits to Drizzt for: WalkSmart method");
		log("************************************************");
		log("*********MysticCrabsPwn3r V" + properties.version()
				+ " started!*********");
		log("*********Let's get some Experience**************");
		log("************************************************");
		if (args.get("charm") != null) {
			charmpickup = true;
		} else {
			charmpickup = false;
		}
		if (args.get("spec") != null) {
			doingspec = true;
		} else {
			doingspec = false;
		}
		if (args.get("ranged") != null) {
			ranging = true;
		} else {
			ranging = false;
		}
		if (args.get("pot") != null) {
			potion = true;
		} else {
			potion = false;
		}
		if (args.get("skill").equals("Attack")) {
			stat = STAT_ATTACK;
			skill = "Attack";
			fightMode = 0;
			potID = new int[] { 121, 122, 123, 124, 125, 126, 145, 146, 147,
					148, 149, 150, 2428, 2429, 2436, 2437, 11429, 11430, 11431,
					11432, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };
		}
		if (args.get("skill").equals("Strength")) {
			stat = STAT_STRENGTH;
			skill = "Strength";
			fightMode = 1;
			potID = new int[] { 113, 114, 115, 116, 117, 118, 119, 120, 157,
					158, 159, 160, 161, 162, 2440, 2441, 11441, 11442, 11443,
					11444, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };

		}
		if (args.get("skill").equals("Defence")) {
			stat = STAT_DEFENSE;
			skill = "Defence";
			fightMode = 3;
			potID = new int[] { 133, 134, 135, 136, 137, 138, 163, 164, 165,
					166, 167, 168, 2432, 2433, 2442, 2443, 11457, 11458, 11459,
					11460, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };
		}
		if (args.get("skill").equals("Accurate Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 0;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		if (args.get("skill").equals("Rapid Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 1;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		if (args.get("skill").equals("Longrange Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 3;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		try {
			if (!args.get("eatt").isEmpty()) {
				eatAT = (skills.getCurrentSkillLevel(3) / 100) * random(25, 33);
			} else {
				eatAT = Integer.parseInt(args.get("eatt") + random(-2, 5));
			}

			if (!args.get("ItemID1").isEmpty()) {
				takeSomeItem = false;
			} else {
				takeSomeItem = true;
				ITPID = Integer.parseInt(args.get("ItemID1"));
			}

		} catch (Exception e) {
		}
		/**
		 * try { URL MySeries = new URL(
		 * "http://i480.photobucket.com/albums/rr163/AlpinePhotos/mcseries-3.gif"
		 * ); MCSeries = ImageIO.read(MySeries); } catch (IOException e) { }
		 */
		return true;
	}

	// What to do when finished
	public void onFinish() {
		Bot.getEventManager().removeListener(PaintListener.class, this);
		Bot.getEventManager().removeListener(ServerMessageListener.class, this);
		log("Thanks for using the script!");
		log("XP per hour: "
				+ ((skills.getCurrentSkillExp(stat) - startExp) * (3600000D / (((double) System
						.currentTimeMillis() - (double) startTime)))));
		log("Levels Gained: " + lvls);
		log("Experience Gained: "
				+ (skills.getCurrentSkillExp(stat) - startExp));
	}

	// Gets Special
	public int getSpec() {
		return getSetting(300);
	}

	// Gets if Special is Enabled
	public boolean specEnabled() {
		return (getSetting(301)) == 1;
	}

	// Does Special!
	public void doSpec() {
		if (getSpec() >= 1000 && !specEnabled() && doingspec == true) {
			openTab(Constants.TAB_ATTACK);
			clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
			wait(350);
			status = "Spec on";
		}
		return;
	}

	// Takes Charms
	public void takeCharms() {
		RSTile charmItems = getGroundItemByID(charms);
		if (charmItems != null) {
			if (getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving() && distanceTo(charmItems) <= 2) {
				clickTile(charmItems, "charm");
				wait(random(300, 850));
			}
		}
		return;
	}

	// Takes Charms
	public void takeArrowz() {
		final RSTile Arrowz = getGroundItemByID(tehArrows);
		if (Arrowz != null) {
			if (getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving() && distanceTo(Arrowz) <= 2) {
				clickTile(Arrowz, "Take " + IDtoName(tehArrows));
				wait(random(300, 850));
			}
		}
		return;
	}

	// Takes Item
	public void takeCustomItem() {
		final RSTile someCustomItem = getGroundItemByID(ITPID);
		if (someCustomItem != null) {
			if (getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving()
					&& distanceTo(someCustomItem) <= 2) {
				clickTile(someCustomItem, "Take " + IDtoName(ITPID));
				wait(random(300, 850));
			}
		}
		return;
	}

	// Does Walking to Crabs
	void Walking() {
		try {
			RSNPC crabbyisdead = getNearestNPCByID(CRAB_ROCK_MODE);

			if (crabbyisdead.getLocation().getX() <= 2691) {
				wait(random(20, 50));
			} else {
				WalkSmart(crabbyisdead);
			}
		} catch (NullPointerException e) {

		}
	}

	public void eat() {
		for (int i = 0; i < FoodID.length; i++) {
			if (getInventoryCount(FoodID[i]) >= 1) {
				clickInventoryItem(FoodID[i], "Eat");
			}
		}
	}

	public boolean needWalkToCenter() {
		if (getMyPlayer().getLocation().getX() <= 2695
				&& getMyPlayer().getAnimation() == -1
				&& getMyPlayer().getInteracting() == null) {
			return true;
		} else {
			return false;
		}
	}

	public boolean needToWalkSouth() {
		if (distanceTo(getNearestNPCByID(CRAB_ROCK_MODE)) <= 1
				&& !getMyPlayer().isInCombat()
				&& distanceTo(getNearestFreeNPCByID(CRAB_NORMAL_MODE)) >= (3)
				&& !getMyPlayer().isMoving()
				&& distanceTo(getNearestFreeNPCByID(CRAB_ROCK_MODE)) <= (1)
				&& getNearestFreeNPCByID(CRAB_ROCK_MODE) != null
				&& getMyPlayer().getAnimation() == -1
				&& getMyPlayer().getInteracting() == null) {
			return true;
		}
		return false;
	}

	public void drinkIt() {
		CurSTAT = skills.getCurrentSkillLevel(stat);
		RealSTAT = skills.getRealSkillLevel(stat);
		if (CurSTAT - RealSTAT <= random(1, 2) && potion == true) {
			for (int i = 0; i < potID.length; i++) {
				if (getInventoryCount(potID[i]) >= 1) {
					clickInventoryItem(potID[i], "Drink");
					status = "Drinking pot..";
					return;
				}
			}
		} else {
			wait(random(20, 30));
			return;
		}
	}

	// Returns if there are some items that has to be looten
	public boolean anyLootItems() {
		RSTile charmItems = getGroundItemByID(charms);
		RSTile Arrowz = getGroundItemByID(tehArrows);
		RSTile someCustomItem = getGroundItemByID(ITPID);

		// Picks up charms
		if (charmItems != null && charmpickup) {
			return anyCharms = true;
		}

		// Picks up any item
		if (someCustomItem != null && takeSomeItem) {
			return anyCustoms = true;
		}

		// Picks up arrows if ranging
		if (Arrowz != null && ranging) {
			return anyArrows = true;
		}

		return false;
	}

	public actions getAction() {
		RSNPC crabbyisdead = getNearestNPCByID(CRAB_ROCK_MODE);
		RSNPC allivecrabby = getNearestNPCByID(CRAB_NORMAL_MODE);

		if (getMyPlayer().getHPPercent() <= random(30, 40)) {
			return actions.EATING;
		}

		CurSTAT = skills.getCurrentSkillLevel(stat);
		RealSTAT = skills.getRealSkillLevel(stat);
		if (CurSTAT - RealSTAT <= random(1, 2) && potion == true) {
			return actions.POTTING;
		}

		if (anyLootItems()) {
			return actions.LOOTING;
		}

		if (needToWalkSouth()) {
			wait(random(500, 1100));
			status = "Walking south..";
			return actions.WALK_SOUTH;
		}

		if (crabbyisdead != null && allivecrabby != null
				&& !allivecrabby.isInteractingWithLocalPlayer()
				&& getMyPlayer().getInteracting() == null) {
			if (!needToWalkSouth()) {
				status = "Walking..";
				return actions.FIGHTING;
			}
		}

		if (needWalkToCenter()) {
			status = "Walking to center..";
			return actions.WALK_CENTER;
		}

		if (distanceTo(goDown) < 5 && !getMyPlayer().isInCombat()) {
			status = "Walking north..";
			return actions.WALK_NORTH;
		}

		return actions.ELIMINATE_SCRIPT;
	}

	public enum actions {
		FIGHTING, WALK_SOUTH, WALK_CENTER, WALK_NORTH, LOOTING, POTTING, EATING, ELIMINATE_SCRIPT
	}

	@Override
	public int loop() {

		while (getMyPlayer().isMoving()) {
			return 800;
		}

		if (getMyPlayer().isMoving() || getMyPlayer().getAnimation() != -1
				|| getMyPlayer().getInteracting() != null) {
			return 450;
		}

		// Does Special and/or Eating if is in Combat
		if (getSpec() >= 1000 && !specEnabled() && doingspec == true) {
			doSpec();
		}

		if (getFightMode() != fightMode) {
			setFightMode(fightMode);
		}

		if (getEnergy() >= runEnergy) {
			if (!isRunning()) {
				setRun(true);
			}
		}

		actions whatToDo = getAction();

		switch (whatToDo) {
		case EATING:
			for (int i = 0; i < FoodID.length; i++) {
				if (getInventoryCount(FoodID[i]) >= 1) {
					clickInventoryItem(FoodID[i], "Eat");
				}
			}
			break;

		case POTTING:
			CurSTAT = skills.getCurrentSkillLevel(stat);
			RealSTAT = skills.getRealSkillLevel(stat);
			if (CurSTAT - RealSTAT <= random(1, 2) && potion == true) {
				for (int i = 0; i < potID.length; i++) {
					if (getInventoryCount(potID[i]) >= 1) {
						clickInventoryItem(potID[i], "Drink");
					}
				}
			} else {
				wait(random(20, 30));
			}
			break;

		case FIGHTING:
			RSNPC crabbyisdead = getNearestNPCByID(CRAB_ROCK_MODE);
			RSNPC allivecrabby = getNearestNPCByID(CRAB_NORMAL_MODE);

			if (getMyPlayer().getInteracting() == null) {
				Walking();
				waitForAnim(1000);
			}
			if (crabbyisdead != null && distanceTo(allivecrabby) <= 1
					&& !crabbyisdead.isInCombat()
					&& getMyPlayer().getInteracting() == null
					&& crabbyisdead.getInteracting() == null) {
				pwnNPC(getNearestFreeNPCByID(CRAB_NORMAL_MODE), "ack");
			}
			break;

		case WALK_SOUTH:
			wait(random(500, 1100));
			walkPathMM(
					randomizePath(fixPath(generateProperPath(goDown)), 2, 2),
					17);
			status = "Walking south..";
			log("Running South");
			break;

		case LOOTING:
			// Takes Charms
			RSTile charmItems = getGroundItemByID(charms);
			if (anyCharms == true) {
				if (charmItems != null) {
					if (getMyPlayer().getInteracting() == null
							&& !getMyPlayer().isMoving()
							&& distanceTo(charmItems) <= 2) {
						clickTile(charmItems, "charm");
						wait(random(300, 850));
					}
				}
			}
			// Takes Arrows
			RSTile Arrowz = getGroundItemByID(tehArrows);
			if (anyArrows == true) {
				if (Arrowz != null) {
					if (getMyPlayer().getInteracting() == null
							&& !getMyPlayer().isMoving()
							&& distanceTo(Arrowz) <= 2) {
						clickTile(Arrowz, "Take " + IDtoName(tehArrows));
						wait(random(300, 850));
					}
				}
			}
			// Takes Custom Items
			final RSTile someCustomItem = getGroundItemByID(ITPID);
			if (anyCustoms) {
				if (someCustomItem != null) {
					if (getMyPlayer().getInteracting() == null
							&& !getMyPlayer().isMoving()
							&& distanceTo(someCustomItem) <= 2) {
						clickTile(someCustomItem, "Take " + IDtoName(ITPID));
						wait(random(300, 850));
					}
				}
			}
			break;

		case WALK_NORTH:
			status = "Walking north..";
			log("Running North");
			walkPathMM(randomizePath(fixPath(generateProperPath(goUp)), 2, 2),
					17);
			break;

		case WALK_CENTER:
			walkPathMM(randomizePath(fixPath(generateProperPath(ToCenter)), 2,
					2), 17);
			status = "Walking to center..";
			log("Walking to Center");
			break;

		}

		return (random(150, 300));
	}

	// Paint of Script, Credits to Noobielul
	public void onRepaint(Graphics g) {
		if (isLoggedIn()) {
			if (startTime == 0) {
				startTime = System.currentTimeMillis();
			}

			if (startLvl <= 0 || startExp <= 0) {
				startLvl = skills.getCurrentSkillLevel(stat);
				startExp = skills.getCurrentSkillExp(stat);
			}

			long millis = System.currentTimeMillis() - startTime;
			long hours = millis / (1000 * 60 * 60);
			millis -= hours * (1000 * 60 * 60);
			long minutes = millis / (1000 * 60);
			millis -= minutes * (1000 * 60);
			long seconds = millis / 1000;

			int x = 0;
			int y = 20;
			g.setColor(new Color(0, 0, 0, 175));
			g.fillRoundRect(0, 20, 220, 120, 10, 10);
			g.fillRect(4, 319, 502, 17);
			g.setFont(new Font("Papyrus", Font.BOLD, 11));
			g.setColor(Color.YELLOW);
			g.drawString("MysticCrabsPwn3r - V" + properties.version(), x + 10,
					y += 15);
			g.setColor(Color.ORANGE);
			g.drawString("Bussy for " + hours + ":" + minutes + ":" + seconds,
					x + 10, y += 15);
			g.drawString("Current " + skill + " level : "
					+ skills.getRealSkillLevel(stat), x + 10, y += 15);
			g.drawString("Gained " + skill + " levels : " + lvls / 2, x + 10,
					y += 15);
			g.drawString("Gained " + skill + " exp : "
					+ (skills.getCurrentSkillExp(stat) - startExp), x + 10,
					y += 15);
			g.drawString("Status : " + status, x + 10, y += 15);
			g
					.drawString(
							"Exp/hour : "
									+ (int) ((skills.getCurrentSkillExp(stat) - startExp) * (3600000D / (((double) System
											.currentTimeMillis() - (double) startTime)))),
							x + 10, y += 15);
			g.drawImage(MCSeries, 55, 360, null);
			g.setColor(Color.ORANGE);
			g.fillRect(5, 320, 5 * skills.getPercentToNextLevel(stat), 15);
			g.setColor(Color.WHITE);
			g.drawString(skills.getPercentToNextLevel(stat) + "%", 250, 331);
		}
	}

	// ServerMessage thingys
	public void serverMessageRecieved(ServerMessageEvent arg0) {
		String crabMessage = arg0.getMessage();
		if (crabMessage.contains("You've just advanced")) {
			lvls++;
			clickContinue();
		}
		if (crabMessage.contains("off")) {
			sendText = nahhhtext[random(0, nahhhtext.length - 1)] + ""
					+ extra2[random(0, extra2.length - 1)];
			sendText(sendText, true);
			wait(random(500, 1000));
		}
	}

	public String IDtoName(int id) {
		try {
			URL url = new URL("http://itemdb-rs.runescape.com/viewitem.ws?obj="
					+ id);
			final BufferedReader reader = new BufferedReader(
					new InputStreamReader(url.openStream()));

			String line;
			int i = 0;
			while ((line = reader.readLine()) != null) {
				if (line.equals("<div class=" + '"' + "subsectionHeader" + '"'
						+ ">")) {
					i++;
					continue;
				}
				if (i == 1) {
					return line;
				}
			}
		} catch (Exception e) {

		}
		return null;
	}

	public String[] IDtoName(int[] ids) {
		ArrayList<String> s = new ArrayList<String>();
		for (int r = 0; r < ids.length; r++) {
			try {
				URL url = new URL(
						"http://itemdb-rs.runescape.com/viewitem.ws?obj="
								+ ids[r]);
				final BufferedReader reader = new BufferedReader(
						new InputStreamReader(url.openStream()));

				String line;
				int i = 0;
				while ((line = reader.readLine()) != null) {
					if (line.equals("<div class=" + '"' + "subsectionHeader"
							+ '"' + ">")) {
						i++;
						continue;
					}
					if (i == 1) {
						s.add(line);
						break;
					}
				}
			} catch (Exception e) {

			}
		}
		return s.toArray(new String[s.size()]);
	}

	// clickTile method by DDM
	public boolean clickTile(RSTile tile, String option) {
		Point p = Calculations.tileToScreen(tile);
		p.x += random(-5, 6);
		p.y += random(-5, 6);
		if (p.x < 0 || p.y < 0) {
			return false;
		}

		moveMouse(p);
		// wait(random(100,150));
		getMenuItems();
		@SuppressWarnings("unused")
		List<String> itemsList = getMenuItems();

		long waitTime = System.currentTimeMillis() + random(50, 250);
		boolean foundOption = false;
		while (System.currentTimeMillis() < waitTime && !foundOption) {
			wait(15);
			foundOption = (itemsList = getMenuItems()).get(0).toLowerCase()
					.contains(option.toLowerCase());
		}
		if (foundOption) {
			clickMouse(true);
			wait(random(150, 300));
			return true;
		}
		clickMouse(false);
		wait(random(150, 300));
		return atMenu(option);
	}

	public boolean pwnNPC(RSNPC npc, String action) {
		if (npc == null) {
			return false;
		}
		RSTile tile = npc.getLocation();
		RSTile randTile = new RSTile(tile.getX() + random(-1, 1), tile.getY()
				+ random(-1, 1));
		if (!tile.isValid()) {
			return false;
		}

		try {
			Point p = Calculations.tileToScreen(tile);
			if (!tileOnScreen(tile) || !pointOnScreen(p)) {
				if (p.x == -1 || p.y == -1) {
					return false;
				}
				p = tileToMinimap(randTile);
				moveMouse(p, 2, 2);
				clickMouse(p, true);
				while (getMyPlayer().isMoving()) {
					wait(random(200, 400));
				}
			}

			for (int i = 0; i < 12; i++) {
				p = Calculations.tileToScreen(randTile);
				if (!npc.isValid() || !pointOnScreen(p)) {
					return false;
				}
				moveMouse(p, 5, 5);
				// wait(random(100,150));
				getMenuItems();
				@SuppressWarnings("unused")
				List<String> itemsList = getMenuItems();

				long waitTime = System.currentTimeMillis() + random(50, 250);
				boolean foundOption = false;
				while (System.currentTimeMillis() < waitTime && !foundOption) {
					wait(15);
					foundOption = (itemsList = getMenuItems()).get(0)
							.toLowerCase().contains(action.toLowerCase());
				}

				if (foundOption) {
					clickMouse(true);
					wait(random(150, 300));
					return true;
				}
				clickMouse(false);
				wait(random(150, 300));
				return atMenu(action);
			}

		} catch (Exception e) {
			System.out.print("pwnNPC(RSNPC, String) error: " + e);
			return false;
		}
		return false;
	}

	// Clicks a NPC by Ruski
	public boolean clickNPC(RSNPC npc, String action) {
		if (npc == null) {
			return false;
		}
		RSTile tile = npc.getLocation();
		if (!tile.isValid()) {
			return false;
		}

		try {
			Point screenLoc = npc.getScreenLocation();
			if (distanceTo(tile) > 6 || !pointOnScreen(screenLoc)) {
				turnToTile(tile);
			}
			for (int i = 0; i < 12; i++) {
				screenLoc = npc.getScreenLocation();
				if (!npc.isValid() || !pointOnScreen(screenLoc)) {
					return false;
				}
				moveMouse(screenLoc, 5, 5);
				if (getMenuItems().get(0).toLowerCase().contains(
						npc.getName().toLowerCase())) {
					break;
				}
				if (getMouseLocation().equals(screenLoc)) {
					break;
				}
			}
			List<String> menuItems = getMenuItems();
			if (menuItems.isEmpty()) {
				return false;
			}
			for (int a = 0; a < menuItems.size(); a++) {
				if (menuItems.get(a).toLowerCase().contains(
						npc.getName().toLowerCase())) {
					if (menuItems.get(0).toLowerCase().contains(
							action.toLowerCase())) {
						clickMouse(true);
						return true;
					} else {
						clickMouse(false);
						return atMenu(action);
					}
				}
			}
		} catch (Exception e) {
			System.out.print("clickNPC(RSNPC, String) error: " + e);
			return false;
		}
		return false;
	}

	// Method for clicking an inventoryItem
	public boolean clickInventoryItem(int itemID, String option) {
		if (getCurrentTab() != TAB_INVENTORY) {
			openTab(TAB_INVENTORY);
		}
		int[] items = getInventoryArray();
		java.util.List<Integer> possible = new ArrayList<Integer>();
		for (int i = 0; i < items.length; i++) {
			if (items[i] == itemID) {
				possible.add(i);
			}
		}
		if (possible.size() == 0) {
			return false;
		}
		int idx = possible.get(random(0, possible.size()));
		Point t = getInventoryItemPoint(idx);
		moveMouse(t, 5, 5);
		long waitTime = System.currentTimeMillis() + random(50, 250);
		boolean found = false;
		while (!found && System.currentTimeMillis() < waitTime) {
			wait(15);
			if ((getMenuItems()).get(0).toLowerCase().contains(
					option.toLowerCase())) {
				found = true;
			}
		}
		if (found) {
			clickMouse(true);
			wait(random(150, 250));
			return true;
		}
		clickMouse(false);
		wait(random(150, 250));
		return atMenu(option);
	}

	// Walks onScreen Option
	public boolean WalkSmart(RSNPC npc) {
		try {
			RSTile t2 = npc.getLocation();
			RSTile t = new RSTile(t2.getX() + random(-1, 1), t2.getY()
					+ random(-1, 1));
			Point p = Calculations.tileToScreen(t);
			if (tileOnScreen(t)) {
				if (clickTile(t, "Walk Here")) {
					while (getMyPlayer().isMoving()) {
						wait(random(200, 400));
					}
					return true;
				}
			} else {
				if (p.x == -1 || p.y == -1)
					return false;
				moveMouse(p, 2, 2);
				clickMouse(p, true);
				while (getMyPlayer().isMoving()) {
					wait(random(200, 400));
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return true;
	}
}